package com.jinyi.wwdeng.ui.main.impl

import com.jinyi.base.mvp.BaseModel
import com.jinyi.base.network.IRequestCallback
import com.jinyi.base.network.NetworkUtils
import com.jinyi.wwdeng.network.ApiService
import com.jinyi.wwdeng.network.HttpBaseParams.addCommonParams
import com.jinyi.wwdeng.ui.main.contract.CreditAuditContract
import org.json.JSONObject

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/28 16:19
 * @Annotation：Model层  接口实现类
 * 贷款审核中、放款中
 */
class CreditAuditModelImpl(iCallback: CreditAuditContract.Presenter): BaseModel<CreditAuditContract.Presenter>(iCallback),CreditAuditContract.Model {
    /**
     * 获取贷款额度信息
     */
    override fun loadCreditLimitInfoRequest() {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_CREDIT_APPLY)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onCreditLimitInfoSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }

    /**
     * 获取推荐安装的App列表
     */
    override fun loadRecommendAppListRequest() {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_RECOMMEND_APP)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onRecommendAppListSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }

    /**
     * 获取评分配置
     */
    override fun loadScoreCommentRequest() {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_SCORE_COMMENT)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onScoreCommentSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }

    /**
     * 获取已绑定的账户列表（法语）
     */
    override fun loadBindAccountListAction() {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_ACCOUNT_LIST_FRENCH)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onBindAccountListSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }

    /**
     * 添加绑定账户（法语）
     */
    override fun addBindAccountAction(mobile: String,walletChannel: String, bindFlag:String) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_ACCOUNT_ADD)
            put("walletMobile",mobile)
            put("walletMobileConfirm",mobile)
            put("walletChannel",walletChannel)
            put("addBindFlag",bindFlag)
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.addBindAccountSuccess(mobile,data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }

    /**
     * 删除账户（法语）
     */
    override fun deleteAccountAction(data: JSONObject) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.API_PATH_ACCOUNT_DELETE)
            put("ids",data.optString("id"))
        }
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onDeleteAccountSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }
}